﻿//#define USE_DUNGEONBUDDY_DLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Media;
using CommonBehaviors.Actions;
using MainDev.RemoteASM.Handlers;
using Styx;
using Styx.Common.Helpers;
using Styx.CommonBot;
using Styx.CommonBot.Frames;
using Styx.Helpers;
using Styx.Patchables;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals.World;
using Action = Styx.TreeSharp.Action;
#if USE_DUNGEONBUDDY_DLL
using Bots.DungeonBuddyDll;
using Bots.DungeonBuddyDll.Profiles;
using Bots.DungeonBuddyDll.Attributes;
using Bots.DungeonBuddyDll.Helpers;
using AvoidanceManager = Bots.DungeonBuddyDll.Avoidance.AvoidanceManager;

namespace Bots.DungeonBuddyDll.Dungeon_Scripts.Mists_of_Pandaria
#else
    using Bots.DungeonBuddy.Profiles;
    using Bots.DungeonBuddy.Attributes;
    using Bots.DungeonBuddy.Helpers;
    using AvoidanceManager = Bots.DungeonBuddy.Avoidance.AvoidanceManager;

namespace Bots.DungeonBuddy.Dungeon_Scripts.Mists_of_Pandaria
#endif
{
    public class LastStandOfTheZandalari : Dungeon
    {
        #region Overrides of Dungeon

        public override uint DungeonId
        {
            get { return 610; }
        }

        public override WoWPoint Entrance
        {
            get { return new WoWPoint(7262.557, 5018.036, 76.17107); }
        }

        public override void RemoveTargetsFilter(List<WoWObject> units)
        {
            units.RemoveAll(
                ret =>
                {
                    var unit = ret.ToUnit();
                    if (unit != null)
                    {

                    }
                    return false;
                });
        }

        public override void IncludeTargetsFilter(List<WoWObject> incomingunits, HashSet<WoWObject> outgoingunits)
        {
            foreach (var obj in incomingunits)
            {
                var unit = obj as WoWUnit;
                if (unit != null) { }
            }
        }

        public override void WeighTargetsFilter(List<Targeting.TargetPriority> units)
        {
            foreach (var priority in units)
            {
                var unit = priority.Object as WoWUnit;
                if (unit != null)
                {
                    if (unit.Entry == HorridonId)
                        priority.Score -= 10000;
                }
            }
        }

        public override void OnEnter()
        {
            if (Me.IsTank())
            {
                Alert.Show(
                    "Tanking Not Supported",
                    string.Format(
                        "Tanking is not supported in the {0} script. If you wish to stay in raid and play manually then press 'Continue'. Otherwise you will automatically leave raid.",
                        Name),
                    30,
                    true,
                    true,
                    null,
                    () => Lua.DoString("LeaveParty()"),
                    "Continue",
                    "Leave");
            }
            else
            {
                Alert.Show(
                    "Do Not AFK",
                    "It is highly recommended you do not afk while in a raid and be prepared to intervene if needed in the event something goes wrong or you're asked to perform a certain task.",
                    20,
                    true,
                    false,
                    null,
                    null,
                    "Ok");
            }
        }

        #endregion

        const uint SpiritFlayerId = 70246;

        private static LocalPlayer Me
        {
            get { return StyxWoW.Me; }
        }

        [EncounterHandler(0)]
        public Composite RootEncounter()
        {
            AddAvoidObject(ctx => true, 9, SpiritFlayerId);
            return new PrioritySelector();
        }

        #region Tortos

        [EncounterHandler(67977, "Tortos-")]
        public Composite TortosBehavior()
        {
            WoWUnit boss = null;
            var roomCenterLog = new WoWPoint(5892.104, 6263.264, 124.0337);
            const float roomRadius = 49;
            return new PrioritySelector(ctx => boss = ctx as WoWUnit);
        }
        #endregion

        #region Megaera

        private const uint MegaeraId = 68065;
        [EncounterHandler(68065, "Megaera")]
        public Composite HorridonBehavior()
        {
            WoWUnit boss = null;
            const uint sandTrapId = 69346;
            const uint frozenOrbId = 69268;
            const uint lightningNovaTotemId = 69215;
            const uint LivingPoisonId = 69313;

            AddAvoidObject(ctx => true, lightningNovaTotemId, lightningNovaTotemId);
            AddAvoidObject(ctx => true, 5, sandTrapId);

            return new PrioritySelector(ctx => boss = ctx as WoWUnit);
        }
        #endregion

        #region Ji-Kun

        public Composite Ji-KunBehavior()
        {
            WoWUnit boss = null;
            return new PrioritySelector(ctx => boss = ctx as WoWUnit);
        }
        #endregion

    }
}